package com.choichumgming.rentcat.service.impl;

import com.choichumgming.rentcat.mapper.AmsCommentMapper;
import com.choichumgming.rentcat.model.AmsComment;
import com.choichumgming.rentcat.model.AmsCommentExample;
import com.choichumgming.rentcat.service.AmsCommentService;
import com.choichumgming.rentcat.service.UmsMemberFeignApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class AmsCommentServiceImpl implements AmsCommentService {
    @Autowired
    private AmsCommentMapper amsCommentMapper;

    @Resource
    private UmsMemberFeignApi umsMemberFeignApi;


    /**
     * @Description : 添加评论
     *
     * @param comment
     * @Return : int
     * @Author : choichumgming
     * @Date : 27/2/2020 23:52
    */
    @Override
    public int add(AmsComment comment) {
        return amsCommentMapper.insert(comment);
    }

    /**
     * @Description : 删除评论
     *
     * @param commentId
     * @Return : int
     * @Author : choichumgming
     * @Date : 27/2/2020 23:53
    */
    @Override
    public int delete(Long commentId) {
        AmsCommentExample example = new AmsCommentExample();
        example.createCriteria().andCommentIdEqualTo(commentId);
        return amsCommentMapper.deleteByExample(example);
    }

    /**
     * @Description : 修改评论
     *
     * @param commentId
     * @param comment
     * @Return : int
     * @Author : choichumgming
     * @Date : 27/2/2020 23:53
    */

    @Override
    public int update(Long commentId, AmsComment comment) {
        AmsCommentExample example = new AmsCommentExample();
        example.createCriteria().andCommentIdEqualTo(commentId);
        return amsCommentMapper.updateByExampleSelective(comment,example);
    }

    /**
     * @Description : 获得指定用户所有评论
     *
     * @param userId
     * @Return : java.util.List<com.choichumgming.rentcat.model.AmsComment>
     * @Author : choichumgming
     * @Date : 27/2/2020 23:53
    */
    @Override
    public List<AmsComment> getUserCommentlist(Long userId) {
        AmsCommentExample example = new AmsCommentExample();
        example.createCriteria().andUserIdEqualTo(userId);
        return amsCommentMapper.selectByExample(example);
    }

    /**
     * @Description : 获得指定文章所有评论
     *
     * @param articleId
     * @Return : com.choichumgming.rentcat.model.AmsComment
     * @Author : choichumgming
     * @Date : 1/3/2020 15:38
     */
    @Override
    public  List<AmsComment>  getArticleComments(Long articleId) {
        AmsCommentExample example = new AmsCommentExample();
        example.createCriteria().andArticleIdEqualTo(articleId);
        List<AmsComment> commentList = amsCommentMapper.selectByExample(example);
        return commentList;
    }

    /**
     * @Description : 获取评论详情
     *
     * @param commentId
     * @Return : com.choichumgming.rentcat.model.AmsComment
     * @Author : choichumgming
     * @Date : 27/2/2020 23:53
    */
    @Override
    public AmsComment getItem(Long commentId) {
        AmsCommentExample example = new AmsCommentExample();
        example.createCriteria().andCommentIdEqualTo(commentId);
        List<AmsComment> commentList = amsCommentMapper.selectByExample(example);
        if(!CollectionUtils.isEmpty(commentList)){
            return commentList.get(0);
        }
        return null;
    }

    /**
     * @Description : 获取当前用户评论列表
     *
     * @param
     * @Return : java.util.List<com.choichumgming.rentcat.model.AmsComment>
     * @Author : choichumgming
     * @Date : 1/3/2020 15:36
    */

}
